/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-12-20 08:51:00
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2023-01-11 09:19:58
 * @FilePath: \adminstration\src\Pages\Front\Common\LargeScreen\Article.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { useEventEmitter, useRequest } from 'ahooks'
import { useState, useEffect } from 'react'
import { Http } from '../../../../Common/Api'
import { LargeScreeTable } from './TablePage'

export const Article = ({ uuid }) => {
    const [Data, setData] = useState()
    const { runAsync: getInfoManageGetOneInfoManage } = useRequest(Http, {
        manual: true,
        onSuccess: res => setData(res[0]),
    })
    useEffect(() => {
        getInfoManageGetOneInfoManage({ url: 'getInfoManageGetOneInfoManage', data: { uuid } })
    }, [getInfoManageGetOneInfoManage, uuid])

    return (
        <div className="Article">
            {Data && (
                <>
                    <div>
                        <div>{Data.tableName}</div>
                        <div>发布时间 : {Data.eventDate}</div>
                    </div>
                    <div dangerouslySetInnerHTML={{ __html: Data.infoContent }} />
                </>
            )}
        </div>
    )
}

const IFRAME = ({ url, path }) => {
    return (
        <iframe
            className="IframeBox"
            title="Video"
            src={url + `?mobile=${path}&appID=10010&from=bada`}
            width="100%"
            height="100%"
            scrolling="no"
            frameBorder="0"
            allowFullScreen={true}
        />
    )
}

const TABLE = ({ className, type, other }) => {
    const classificationList = { plan: 'PlanStatAttachmentTableList', metering: 'MeterageAttachmentTableList' }
    const ExperimentalThrEvent = useEventEmitter()
    ExperimentalThrEvent.useSubscription(val => {
        console.log(val)
    })
    return (
        <LargeScreeTable
            className={className}
            classification={classificationList[type]}
            ExperimentalThrEvent={ExperimentalThrEvent}
            other={other}
        />
    )
}

export const IframeBox = ({ classification, other, className }) => {
    const [IframeList] = useState({
        plan: 'http://cloud.ljkjkf.com/external/planStatExaminationGrid',
        metering: 'http://cloud.ljkjkf.com/external/report',
    })
    const { path } = other
    return (
        <>
            {path !== 'null' ? (
                <IFRAME url={IframeList[classification]} path={path} />
            ) : (
                <TABLE className={className} type={classification} other={other} />
            )}
        </>
    )
}
